﻿//Write a method that counts how many times given number appears in given array.
//Write a test program to check if the method is working correctly.

using System;
class CountNumberInArray
{
    static void Main()
    {
        Console.WriteLine("Please, specify array's length");
        int arrayLength = int.Parse(Console.ReadLine());

        int[] array = new int[arrayLength];

        Console.WriteLine("Please, enter array's elements");

        for (int i = 0; i < array.Length; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }

        Console.WriteLine("Please, enter the number we search");
        int repeatedNumber = int.Parse(Console.ReadLine());

        Console.WriteLine("The number {0} repeats {1} times", repeatedNumber, NumCounterInArray(array, repeatedNumber));
    }

    static int NumCounterInArray(int[] array, int number)
    {
        Array.Sort(array);

        int counter = 1;

        for (int i = 0; i < array.Length - 1; i++)
        {
            if ((array[i] == number) && (array[i] == array[i + 1]))
            {
                counter++;
            }
        }

        return counter;
    }
}
